using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_PROGDEF
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {
            switch (app.company)
            {
                default:
                case "YGR":
                    #region
                    dwReturn["MANDANT"] = "00";
                    dwReturn["ROWNID"] = "0";
                    dwReturn["PROG"] = "";
                    dwReturn["CONTROLS"] = "";
                    dwReturn["REMARK"] = "";
                    dwReturn["P1"] = "";
                    dwReturn["P2"] = "";
                    dwReturn["P3"] = "";
                    dwReturn["NEWUSER"] = "";
                    dwReturn["NEWTIME"] = "";
                    dwReturn["CHGUSER"] = "";
                    dwReturn["CHGTIME"] = "";
                    #endregion
                    break;
            }
        }
        public void InsertICC_PROGDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["NEWUSER"] = app.User;
            dwData["NEWTIME"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                    or1.CommandText = "INSERT INTO ICC_PROGDEF ( MANDANT,ROWNID,PROG,CONTROLS,REMARK,P1,P2,P3,NEWUSER,NEWTIME,CHGUSER,CHGTIME)"
                + " VALUES (:MANDANT:,:ROWNID:,:PROG:,:CONTROLS:,:REMARK:,:P1:,:P2:,:P3:,:NEWUSER:,:NEWTIME:,:CHGUSER:,:CHGTIME:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_PROGDEF(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_PROGDEF WHERE  ROWNUM<2 ";
                    break;
                case 2:
                    or1.CommandText = "SELECT DISTINCT P.*,CONTROLS AS KEY,REMARK AS DES FROM ICC_PROGDEF P WHERE PROG=:PROG: "
                        + " ORDER BY PROG,CONTROLS";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -1:
                    or1.CommandText = "SELECT * FROM ICC_PROGDEF"
                        + " ORDER BY PROG,CONTROLS";
                    break;
                case -2:
                    or1.CommandText = "SELECT DISTINCT PROG,TRIM(PROG) AS KEY,TRIM(PROG) AS DES FROM ICC_PROGDEF P  "
                    +" ORDER BY PROG";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -3:
                    or1.CommandText = "SELECT PROG,CONTROLS,TRIM(CONTROLS) AS KEY,REMARK,TRIM(REMARK) AS DES FROM ICC_PROGDEF P WHERE TRIM(PROG)=:PROG: "
                    + " ORDER BY PROG,CONTROLS";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PROGDEF";
            return SResult;
        }
        public void DeleteICC_PROGDEF(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "DELETE FROM ICC_PROGDEF   " ; 
                    break;
                case 1:
                    or1.CommandText = "DELETE FROM ICC_PROGDEF   "
                        + " WHERE  MANDANT=:MANDANT: AND ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateICC_PROGDEF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            dwData["CHGUSER"] = app.User;
            dwData["CHGTIME"] = date;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                default:
                case 1:
                    or1.CommandText = "UPDATE ICC_PROGDEF SET MANDANT=:MANDANT:,ROWNID=:ROWNID:,PROG=:PROG:,CONTROLS=:CONTROLS:,REMARK=:REMARK:,P1=:P1:,P2=:P2:,P3=:P3:,NEWUSER=:NEWUSER:,NEWTIME=:NEWTIME:,CHGUSER=:CHGUSER:,CHGTIME=:CHGTIME:"
                        + " WHERE  MANDANT=:MANDANT: AND ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            } 
            Connect2Proxy(or1);
        }
    }
}
